package com.dykj.fireFighting.server.fire.contractMessage.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dykj.fireFighting.api.fire.contractMessage.dto.ContractMessageDto;
import com.dykj.fireFighting.api.fire.contractMessage.entity.ContractMessage;
import com.dykj.fireFighting.api.fire.contractMessage.service.IContractMessageService;
import com.dykj.fireFighting.api.fire.contractMessage.vo.ContractMessagesVo;
import com.dykj.fireFighting.common.core.service.impl.BaseServiceImpl;
import com.dykj.fireFighting.common.core.vo.PageVo;
import com.dykj.fireFighting.server.fire.contractMessage.mapper.ContractMessageMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 维保合同表
 *
 * @Author JacksonTu
 * @Date 2021-07-27 15:01:44
 */
@Slf4j
@DubboService
@Transactional(rollbackFor = Exception.class)
public class ContractMessageServiceImpl extends BaseServiceImpl<ContractMessageMapper, ContractMessage> implements IContractMessageService {


    @Override
    public PageVo<ContractMessagesVo> queryList(ContractMessageDto contractMessageDto) {
        HashMap<String, Object> params = new HashMap<>(16);
        params.put("wbId", contractMessageDto.getWeibaoUnitsCode());
        params.put("shId",contractMessageDto.getSocialUnitsCode());
        params.put("contractNumber",contractMessageDto.getContractNumber());
        params.put("name",contractMessageDto.getName());
        if (StringUtils.isNotBlank(contractMessageDto.getExpirationDate()) && StringUtils.isNotBlank(contractMessageDto.getEffectiveDate())) {

            params.put("beginDate", contractMessageDto.getEffectiveDate());
            params.put("endDate", contractMessageDto.getExpirationDate());
        }

        Page page = new Page();
        // 设置当前页码
        page.setCurrent(contractMessageDto.getPage());
        // 设置页大小
        page.setSize(contractMessageDto.getLimit());
        return new PageVo<ContractMessagesVo>(this.baseMapper.queryList(page, params));
    }

    @Override
    public List<ContractMessagesVo> getSomeContract(HashMap<String, Object> params) {

        return this.baseMapper.getSomeContract(params);
    }

    @Override
    public List<ContractMessagesVo> getBeExpireList(String unitId ,Integer type) {
        //获取快到期的合同列表
        return this.baseMapper.queryBeExprieList(unitId,type);
    }

    @Override
    public List<ContractMessagesVo> getUnitList(HashMap<String, Object> params) {
        return this.baseMapper.getUnitList(params);
    }

    @Override
    public ContractMessagesVo getByUnitMaintenance(String sociolgyId, String maintenanceId) {
        return this.baseMapper.getByUnitMaintenance(sociolgyId,maintenanceId);
    }

    /**
     * 查询相同合同号的个数
     * @param contractNumber
     * @return
     */
    @Override
    public int querySameContractNumSize(String contractNumber,String id) {
        return this.baseMapper.querySameContractNum(contractNumber, id);
    }
}
